<form action="" id="myform" class="gj_view">
<?php foreach($find_customer as $find_customer):?>
<div id="inline1">
<h2><span>客户信息</span></h2>
  <table>
        <tr><th colspan="7">基本信息：</th></tr>
        <tr bgcolor="#FDECCA" height="30" style=" width:512px; color:#000;">
        	<td width="80" align="right">客户名称：</td>
            <td>&nbsp;</td>
            <td colspan="5" id="customer_name"><?= $find_customer->customer_name?></td>
        </tr>
        <tr>
            <td class="name" width="80">共享：</td>
            <td>&nbsp;</td>
            <td colspan="5"><?= $find_customer->share?></td>
        </tr>
        <tr>
        	<td class="name" width="80">所属区域：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $region_name?></td>
            <td>&nbsp;</td>
            <td class="name" width="80">标签：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->tag?></td>
        </tr>
        <tr>
        	<td class="name" width="80">上级客户：</td>
            <td>&nbsp;</td>
            <td width="170">
            <?= $find_customer->superior_customer?>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">三产公司：</td>
            <td>&nbsp;</td>
            <td colspan="5" width="170"><?= $find_customer->produce_company?></td>
        </tr>
        <tr>
            <td class="gj_name">公司简介：</td>
            <td>&nbsp;</td>
            <td height="80" colspan="5" valign="top"><?= $find_customer->company_introduce?></td>
        </tr>
        <tr><th colspan="7">联系方式：</th></tr>
        <tr>
        	<td class="name" width="80">邮编：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->email?></td>
            <td>&nbsp;</td>
            <td class="name" width="80">电话：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->phone?></td>
        </tr>
        <tr>
            <td class="name" width="80">传真：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->fax?></td>
            <td>&nbsp;</td>
            <td class="name" width="80">省份：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->province?></td>
        </tr>
        <tr>
            <td class="name" width="80">城市：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->city?></td>
            <td>&nbsp;</td>
            <td class="name" width="80">区县：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->county?></td>
        </tr>
        <tr>
            <td class="name" width="80">地址：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->address?></td>
            <td>&nbsp;</td>
            <td class="name" width="80">网址：</td>
            <td>&nbsp;</td>
            <td width="170"><?= $find_customer->website?></td>
        </tr>
        <tr>
            <td class="gj_name">备注：</td>
            <td>&nbsp;</td>
            <td height="80" colspan="5" valign="top"><?= $find_customer->remark?></td>
        </tr>
        <tr><td colspan="7">&nbsp;</td></tr>
        
  </table>
</div>
<div class="view_inline1">
    <table>
      <tr class="view_inline1_1"><th class="view_tit_l">日程</th><th align="right" class="view_tit_r">
      <a href="index.php/customer/add_schedule/<?=$find_customer->id?>" class="various1" id="find">新建</a></th></tr>
        <?php foreach($find_schedules as $find_schedule):?>
        <?php  $createtime = substr($find_schedule->create_time, 0, 10);
        	   $subject = substr($find_schedule->subject, 0, 36);
        ?>
		  <tr>
        	<td colspan="2">
        	<a href="index.php/schedule/check/<?= $createtime?>/<?= $find_schedule->schedule_id?>" class="various1" id="find">
        	<?= $subject?></a>&nbsp;&nbsp;&nbsp;&nbsp;<?= $createtime?></td>
    	  </tr>
		<?php endforeach;?>
		
		<tr class="view_inline1_4"><th class="view_tit_l">联系人</th><th align="right" class="view_tit_r">
        <a href="index.php/contacter/show_contacter_add/<?=$find_customer->customer_name?>" class="various1" id="find">新建</a></th></tr>
		<?php foreach($find_contacters as $find_contacter):?>
		<?php  $createtime = substr($find_contacter->create_time, 0, 10);?>
        <tr>
        	<td colspan="2"><a href="index.php/contacter/find/<?= $find_contacter->id?>" class="various1" id="find">
        	<?= $find_contacter->name?></a>&nbsp;&nbsp;&nbsp;&nbsp;<?= $createtime?></td>
      	</tr>
      	<?php endforeach;?>
		
        <tr class="view_inline1_2">
        <th class="view_tit_l">销售机会</th>
        <th align="right" class="view_tit_r"><a href="index.php/opportunity/show_contacter_add/<?=$find_customer->customer_name?>"  class="various1" id="find">新建</a></th></tr>
	        <?php foreach($find_opportunitys as $find_opportunity):?>
	        <?php  $createtime = substr($find_opportunity->create_time, 0, 10);?>
	        <tr>
	       	  <td colspan="2">
	       	  <a href="index.php/opportunity/find/<?= $find_opportunity->id?>"  class="various1" id="find">
	       	  <?= $find_opportunity->subject?></a>&nbsp;&nbsp;&nbsp;&nbsp;<?= $createtime?></td>
	    	</tr>
			<?php endforeach;?>
			
        <tr class="view_inline1_3"><th class="view_tit_l">合同订单</th><th align="right" class="view_tit_r">
        <a href="index.php/contract/show_contract_add/<?=$find_customer->customer_name?>/<?=$find_customer->id?>" class="various1" id="find">新建</a></th></tr>
        <?php foreach($find_contracts as $find_contract):?>
        <?php  $createtime = substr($find_contract->create_time, 0, 10);?>
        <tr>
       	  <td colspan="2"><a href="#"><?= $find_contract->subject?></a>&nbsp;&nbsp;&nbsp;&nbsp;<?= $createtime?></td>
    	</tr>
		<?php endforeach;?>
		
        <tr class="sub">
            <td colspan="7"><input type="button" id="c_c_v_e" value="编辑" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="c_c_v_d" value="删除" /></td>
        </tr>
        <tr><td colspan="2">&nbsp;</td></tr>
    </table>
</div>
<input type="hidden" id="hi_customer_id" value="<?= $find_customer->id?>"/>
<?php endforeach;?>
</form>
<!--编辑-->
<form action="index.php/customer/update/" method="post" name="update_myform" id="update_myform" class="g_view">
<div id="inline1">
<h2><span>客户信息</span></h2>
	<table>
        <tr><th colspan="5">基本信息：</th></tr>
        <tr bgcolor="#FDECCA" height="30">
          <td class="name" width="80" align="right" style=" color:#000;"><span>*</span>客户名称：</td>
          <td colspan="4" id="customer_name"><input type="text" style="width:427px;"  name="customer_name" value=<?= $find_customer->customer_name?> ></input></td>
        </tr>
        <tr>
          <td class="name" width="80">共享：</td>
          <td colspan="4">
          	<input type="text" name="share" id="ele1"  style="width:427px;" value="<?= $find_customer->share?>"></input>
            <div id="blk1" class="blk" style="display:none;">
               <!-- <div class="head"><div class="head-right"></div></div>-->
                <div class="mains">
                    <h2>请选择您要共享的用户</h2>
                    <a href="javascript:void(0)" id="close1" class="closeBtn close1" title="关闭">X</a>
                    <ul>
                       <?php
                       	$array = explode(' ',$find_customer->share);
                       ?>
						<?php foreach($users as $item):?>
							<li class="li_input">
								<input type="checkbox" name="checkbox" id="" value="<?= $item->user_name?>" <?php if(in_array($item->user_name,$array)):?> checked="checked" <?php endif;?>/>
								<span style="cursor:pointer"><?= $item->user_name?></span>
							</li>
						<?php endforeach;?>
                    </ul>
                    <div class="share_sub"><input type="button" id="tijiao" class="close1" value="确定" /><input type="button" class="allselect" value="全选" /><input type="button" class="cancel" value="取消全选" /></div>
                    <script type="text/javascript">
                    $(document).ready(function(){
                    	if($("#hi_username").val()){
                    		var boxval=$("#hi_username").val();
                    		boxval=boxval+' ';
                        }else{
                        	var boxval='';
                        }
                    	var allselect='';
                        $(".allselect").click(function(){
                            $(".li_input input").each(function(){
                                $(this).attr("checked",true);
								boxval+=$(this).val()+' ';
                            });
							$(".allselect").hide();
							$(".cancel").show();
							allselect=1;
                        });
                        //取消
                        $(".cancel").click(function(){
                            $(".li_input input").each(function(){
                                $(this).attr("checked",false);
                            });
							$(".allselect").show();
							$(".cancel").hide();
							boxval = '';
                        });
						//点击span
						$("span").bind("mouseover",function(){}).bind("click",function(){
						//  由span标签获取input标签
							var obj=$(this).parent().children(0);
							if(obj.attr("checked")==true){ obj.removeAttr("checked"); }
							else { obj.attr("checked","checked"); }
						});
						//添值
                        $("#tijiao").click(function(){
                        	if(allselect){
                        		boxval = '';
							}
                        	$(":checkbox:checked").each(function(){
                    		 	boxval+=$(this).val()+' ';
                    		});
							$("#ele1").val(boxval);
							$(".li_input input").attr("checked",false);
							boxval = '';
                        });
                    });
                    </script>
                </div>
            </div>
          </td>
        </tr>
        <tr>

        <td class="name" width="80">上级客户：</td>
            <td width="170">
            	<select name="parent_id" id="superior">
                		<option selected="selected" value="0">请选择上级客户</option>
						<?php foreach($all_customers as $all_customer):?>
								<option value="<?= $all_customer->id?>" <?php if($all_customer->customer_name == $find_customer->superior_customer):?> selected="selected" <?php endif;?>>
								<?php if($all_customer->parent_id <> 0):?>──<?php endif;?><?= $all_customer->customer_name?></option>
						<?php endforeach;?>
                </select>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">标签：</td>
            <td width="170"><input type="text" name="tag" value=<?= $find_customer->tag?> ></input></td>
        </tr>
        <tr>
            <td class="name" width="80" >所属区域：</td>
            <td width="170">
            	<select name="region_id" id="dirtrict">
                	<option selected="selected" value='0'>请选择</option>
                    <?php foreach($region as $item):?>
						<option value="<?= $item->id?>"  <?php if($find_customer->region_id == $item->id):?> selected="selected" <?php endif;?>><?= $item->district?></option>
					<?php endforeach;?>
                </select>
            </td>
            <script type="text/javascript">
 					$(function(){
 	 					var $superior_customer = $("#superior");
 	 					$superior_customer.change(function(){
 	 						var customer_id = $superior_customer.val();
							$.ajax({
				                type: "POST",
				                dataType: "text",
				                url: "index.php/customer/check_region",
				                data: "customer_id="+customer_id,
				                success: function(data) {
				                	data=$.parseJSON(data);
				                	var region_id = data['region_id'];
             	                	var district = data['district'];
             	                	if(region_id == null || district == null){
                 	                	alert('对应客户未选择区域,请检查数据完整性,或手动输入区域');
                 	                }else{
                 	                	var array="<option value="+region_id+">"+district+"</option>";
                 	                	var $dirtrict = $("#dirtrict");
                 	                	$dirtrict.html('');
                 	                	$dirtrict.append(array);
                         	        }
				                },
				                error: function(){
									alert('对不起,请求出现异常,请重新进行请求');
						        }
				            });
							})
 	 	 			})
                </script>
            <td>&nbsp;</td>
            <td class="name" width="80">三产公司：</td>
            <td colspan="4" width="170"><input type="text" name="produce_company" value=<?= $find_customer->produce_company?> ></input></td>
        </tr>
        <?php
                    		$user_name = $this->session->userdata('username');
                       		$role = $this->session->userdata('role');
                       		?>
        <?php if($role == '商务助理' || $role == '经理'):?>
        <tr>
            <td class="name" width="80">所有者：</td>
            <td width="170" colspan="5">
                    <select name="user_id">
                    	<?php foreach ($all_users as $item_user):?>
                    		<?php if($item_user->user_name != '何俊斌'):?>
                    			<option value="<?= $item_user->id?>" <?php if($item_user->user_name == $user_name):?> selected='selected' <?php endif;?>><?= $item_user->user_name?></option>
                    		<?php endif;?>
                        <?php endforeach;?>
                        </select>	
            </td>
        </tr>
        <?php endif;?>
        <?php if($role == '市场'):?>
        	<input type="hidden" name="user_id" value= >
        <?php endif;?>
        <tr>
            <td class="gj_name">公司简介：</td>
            <td colspan="5"><textarea name="company_introduce" ><?= $find_customer->company_introduce?></textarea></td>
            <td>&nbsp;</td>
        </tr>
        <tr><th colspan="5">联系方式：</th></tr>
        <tr>
            <td class="name" width="80">邮编：</td>
            <td width="170"><input type="text" name="email"  value=<?= $find_customer->email?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">电话：</td>
            <td width="170"><input type="text" name="phone" value=<?= $find_customer->phone?>></input></td>
        </tr>
        <tr>
            <td class="name" width="80">传真：</td>
            <td width="170"><input type="text" name="fax"  value=<?= $find_customer->fax?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">省份：</td>
            <td width="170"><input type="text" name="province"  value=<?= $find_customer->province?> ></input></td>
        </tr>

        <tr>
            <td class="name" width="80">城市：</td>
            <td width="170"><input type="text"  name="city" value=<?= $find_customer->city?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">区县：</td>
            <td width="170"><input type="text" name="county"  value=<?= $find_customer->county?> ></input></td>
        </tr>
        <tr>
            <td class="name" width="80">地址：</td>
            <td width="170"><input type="text" name="address" value=<?= $find_customer->address?> ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">网址：</td>
            <td width="170"><input type="text" name="website"  value=<?= $find_customer->website?> ></input></td>
        </tr>
        <tr>
            <td class="gj_name">备注：</td>
            <td colspan="5"><textarea name="remark" ><?= $find_customer->remark?></textarea></td>
        </tr>
        <tr><td colspan="5">&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="edit_tijiao" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" id="c_c_v_back" value="返回" /></td>
        </tr>
    </table>
</div>
<input type="hidden" name="id" value=<?= $find_customer->id?> />
<input type="hidden" name="offset" value="0" />
</form>
<?php if(($update_customer->user_id != $this->session->userdata('id')) && ($this->session->userdata('role')!= '经理')&& ($this->session->userdata('role')!= '商务助理')):?>
<input type="hidden" id="hi_username" value=<?= $this->session->userdata('username')?> >
<?php endif;?>
<!--编辑-->
<script language="javascript">
	$(document).ready(function() {
		new PopupLayer({trigger:"#ele1",popupBlk:"#blk1",closeBtn:".close1",useOverlay:true}); //<!--共享弹出框-->
		
		$(".g_view").hide();
		$("#c_c_v_e").click(function(){
			$(".gj_view").hide();
			$(".g_view").show();
		});
		
		$("#c_c_v_back").click(function(){
			$(".gj_view").show();
			$(".g_view").hide();
		});
		
		jQuery.ajaxSetup ({cache:false}); /*让ajax不调用浏览的缓存*/
		$(".various1").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'hideOnOverlayClick' : false,
		'onComplete'	: function() {
				var suggest = new GoogleSuggest("myform", "customer_name", 0);
			}
		});

		$("#edit_tijiao").click(function(){
			var error="";
			var name=$(":input[name='customer_name']").val();
			if($.trim(name) == ""){
				 error="错误：\x0d";
	             error+="客户名称不允许为空,请填写\x0d";
	             $(":input[name='customer_name']").focus();
		    }
	        if(error != ""){
	        	alert(error);
	        }else{
		        $("#update_myform").submit();
	        }
		})

		$("#c_c_v_d").click(function(){
			if (window.confirm("您确定要删除吗？")) {
				var customer_id_val = $("#hi_customer_id").val();
				location.href="<?= base_url()?>index.php/customer/delete/"+customer_id_val;
			}
		})
	});
</script>
